home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / examples / exam16 / class1.d < prev    next >
Text File  |  1995-09-27  |  3KB  |  122 lines

  1.  
  2.  
  3.  
  4.  
  5. /*
  6.  *
  7.  *    This source code is CONFIDENTIAL and
  8.  *    PROPRIETARY to Algorithms Corporation. Unauthorized
  9.  *    distribution, adaptation or use    may
  10.  *    be subject to civil and    criminal penalties.
  11.  *
  12.  *    Copyright (c) 1993 Algorithms Corporation
  13.  *    3020 Liberty Hills Drive
  14.  *    Franklin, TN  37064
  15.  *
  16.  *    ALL RIGHTS RESERVED.
  17.  *
  18.  *
  19.  *
  20.  */
  21.  
  22.  
  23. defclass  Class1  {
  24.     char    iName[30];
  25.     int    iCode;
  26.     iData;
  27.   class:
  28.       int    cNumInstances;
  29. };
  30.  
  31.  
  32. cmeth    gNewWithInt(int code)
  33. {
  34.     /*  Declare an object which will hold the new instance object being
  35.         created.  */
  36.     object    obj;
  37.  
  38.     /*  Declare a pointer which will point to the instance variables
  39.         associated with the new instance.  'ivType' refers to a C
  40.         structure which looks like the instance variable structure
  41.         defined in the defclass.  The name of the pointer must be 'iv'.
  42.         This is so Dynace knows how to access the instance variables
  43.         when they are refered to without the normal C iv-> construct.  */
  44.     ivType    *iv;
  45.  
  46.     /*  Increment the count as before.  */
  47.     cNumInstances++;
  48.  
  49.     /*  Create the new instance object as before, only this time put it
  50.         in obj.  */
  51.     obj = gNew(super);
  52.  
  53.     /*  Gain access to a pointer to the locally defined instance variables
  54.         associated with obj and assign it to iv.  Note that this procedure,
  55.         which is required to access instance variables, is performed
  56.         automatically on the self object on instance methods.  That is
  57.         why instance methods may directly access instance variables
  58.         associated with their self argument without the need for the
  59.         ivPtr or ivsPtr macros.  */
  60.     iv = ivPtr(obj);
  61.  
  62.     /*  Since iv is correctly updated it is now safe to directly access
  63.         the instance variables associated with obj - update iCode with
  64.         the 'code' value passed to this method.  */
  65.     iCode = code;
  66.  
  67.     /*  Since we are now through allocating and initializing the new
  68.         object, simply return it.  */ 
  69.     return obj;
  70. }
  71.  
  72. /*  Create an instance method to allow an external program to access the
  73.     value in iCode in order to test our New method.  */
  74.     
  75. imeth    int    gGetCode()
  76. {
  77.     return iCode;
  78. }
  79.  
  80. cmeth    int    gNumInstances()
  81. {
  82.     return cNumInstances;
  83. }
  84.  
  85. imeth    object    gDeepDispose, gDispose ()
  86. {
  87.     cNumInstances--;
  88.     gDispose(super self);
  89.     return NULL;
  90. }
  91.  
  92. imeth    gSetName(char *name)
  93. {
  94.     strcpy(iName, name);
  95.     return self;
  96. }
  97.  
  98. imeth    char    * gGetName : get_name ()
  99. {
  100.     return iName;
  101. }
  102.  
  103.  
  104. /*
  105.  *
  106.  *    This source code is CONFIDENTIAL and
  107.  *    PROPRIETARY to Algorithms Corporation. Unauthorized
  108.  *    distribution, adaptation or use    may
  109.  *    be subject to civil and    criminal penalties.
  110.  *
  111.  *    Copyright (c) 1993 Algorithms Corporation
  112.  *    3020 Liberty Hills Drive
  113.  *    Franklin, TN  37064
  114.  *
  115.  *    ALL RIGHTS RESERVED.
  116.  *
  117.  *
  118.  *
  119.  */
  120.  
  121.  
  122.